<set-name>={value1,value2,...,valueN}
<set_name>=set(iterable)
Months={"Jan","Feb","Mar"} lst=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"] Days=set(lst)
{'Feb', 'Mar', 'Jan'} {'Mon', 'Tue', 'Wed', 'Fri', 'Sun', 'Sat', 'Thu'}
for var in set-object: statement ---------
Functions | |
---|---|
add(value) | Adds an element to the set. |
clear() | Removes all the elements from the set. |
copy() | Returns a copy of the set. |
pop() | removes a random item from the set. |
remove(value) | The method will raise an error if the specified item does not exist. |
discard(value) | Removes the specified element. |
union(collection) | Return a set containing the union of sets. |
update(collection) | Update the set with the union of this set and others. |
intersection(collection) | Returns a set, that is the intersection of two other sets. |
intersection_update(collection) | Removes the items in this set that. are not present in other, specified set. |
difference(collection) | The difference operation on two sets produces a new set containing only the elements from the first set and none from the second set. |
difference_update(collection) | Removes the items in this set that are also included in another, specified set. |